{extend name="public:adminbase" /}

{block name="content"}


<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-header">
          <h4>文章列表</h4>
        </div>
        <div class="card-toolbar clearfix">
          <form class="pull-right search-bar" method="get" action="{:url('AdminArticle/index')}" role="form">
            <div class="input-group">
              <div class="input-group-btn">
                <input type="hidden" name="search_field" id="search-field" value="title">
                <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                标题 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a> </li>
                  <li> <a tabindex="-1" href="javascript:void(0)" data-field="id">id</a> </li>
                </ul>
              </div>
              <input type="text" class="form-control" value="<?php if(request()->param('keyword')){echo request()->param('keyword');}?>" name="keyword" placeholder="请输入名称">
            </div>
          </form>
          <div class="toolbar-btn-action">
            <a target="_blank" class="btn btn-primary m-r-5" href="{:url('Article/create')}"><i class="mdi mdi-plus"></i> 新增</a>


            <a onclick="openframe('importWord')" class="btn btn-success m-r-5" href="javascript:;"><i class="mdi mdi-check"></i> 导入Word</a>
            <!--<a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a>-->
            <a class="btn btn-danger" href="javascript:;" onclick="del_all()"><i class="mdi mdi-window-close"></i> 批量删除</a>
            <button class="btn btn-danger" id="dosubmit"><i class="mdi mdi-cloud"></i>推送到百度站长seo</button>
            <button class="btn " id="sitemap"><i class="mdi mdi-sitemap"></i>更新sitemap</button>

            <script>
                document.getElementById("s1").onchange = function(){
                    console.log(this.options[this.selectedIndex].innerHTML);
                    //console.log(this.options[this.selectedIndex].value);
                    var value = this.options[this.selectedIndex].value;
                    var  url = "{:url()}&order="+value
                    console.log(url);
                    location.href = url
                }
            </script>

            <form class="pull-right" method="get" action="{:url('AdminArticle/index')}" role="form">

              <select class="form-control" name="model_id" size="1" style="width: 100px; float:left;">
                <option value="0">类型筛选</option>
                {foreach $models as $v}
                <option value="{$v.id}" {if input('param.model_id') == $v.id}selected{/if}>
                {$v.name}
                </option>
                {/foreach}
              </select>

              <select class="form-control" id="article-select" name="cate_id" size="1">
                <option value="0">按照分类筛选</option>
                {foreach $cate as $v}
                <option value="{$v.id}" {if input('param.cate_id') == $v.id}selected{/if}>
                  {if $v.level > 1}
                  {for start="1" end="$v.level * 2"}
                    &nbsp;
                  {/for}
                  {/if}

                {$v.name}
                </option>
                {/foreach}
              </select>



              <button type="submit"  class="btn btn-primary m-r-5 " >确认</button>
            </form>
          </div>
        </div>
        <div class="card-body">
          
          <div class="table-responsive">
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" id="check-all"><span></span>
                    </label>
                  </th>
                  <th>编号
                    {if request()->param("order") == 'id_desc'}
                    <a href="{:url_param('order','id_asc')}" title="升序排列"><i class="mdi mdi-arrow-expand-up"></i></a>
                    {else/}
                    <a href="{:url_param('order','id_desc')}" title="降序排列"><i class="mdi mdi-arrow-expand-down"></i></a>
                    {/if}
                  </th>
                  <th>类型</th>
                  <th>分类</th>
                  <th width="400">标题</th>
                  <th>点击
                    {if request()->param("order") == 'hit_desc'}
                    <a href="{:url_param('order','hit_asc')}" title="升序排列"><i class="mdi mdi-arrow-expand-up"></i></a>
                    {else/}
                    <a href="{:url_param('order','hit_desc')}" title="降序排列"><i class="mdi mdi-arrow-expand-down"></i></a>
                    {/if}
                  </th>
                  <th>排序
                    {if request()->param("order") == 'oid_desc'}
                    <a href="{:url_param('order','oid_asc')}" title="升序排列"><i class="mdi mdi-arrow-expand-up"></i></a>
                    {else/}
                    <a href="{:url_param('order','oid_desc')}" title="降序排列"><i class="mdi mdi-arrow-expand-down"></i></a>
                    {/if}
                  </th>
                  <th>状态
                    {if request()->param("order") == 'status_desc'}
                    <a href="{:url_param('order','status_asc')}" title="升序排列"><i class="mdi mdi-arrow-expand-up"></i></a>
                    {else/}
                    <a href="{:url_param('order','status_desc')}" title="降序排列"><i class="mdi mdi-arrow-expand-down"></i></a>
                    {/if}
                  </th>
                  <th>置顶</th>
                  <th>推荐</th>
                  <th>热度</th>
                  <th>创建</th>
                  <th>百家号</th>
                  <th>修改</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                {foreach $list as $v}
                <tr>
                  <td>
                    <label class="lyear-checkbox checkbox-primary">
                      <input type="checkbox" name="ids[]" value="{$v.id}"><span></span>
                    </label>
                  </td>
                  <td>{$v.id}</td>
                  <td>{$v.mod.name}</td>
                  <td>{$v.cate.name}[{$v.cate.id}]</td>
                  <td>{$v.title}</td>
                  <td>{$v.rel_hits}</td>
                  <td>{$v.ordid}</td>
                  <td>
                    {switch $v.status}
                    {case 1 }<button data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-primary btn-xs">已发</button>{/case}
                    {case 2 }<button data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-warning btn-xs">草稿</button>{/case}
                    {default /}<button data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-primary btn-xs">已启用</button>
                    {/switch}
                  </td>
                  <td>
                    {switch $v.top}
                    {case 1 }<button onclick="change_top({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-primary btn-xs">是</button>{/case}
                    {default /}<button onclick="change_top({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-secondary btn-xs">否</button>
                    {/switch}
                  </td>
                  <td>
                    {switch $v.recommend}
                    {case 1 }<button onclick="change_recommend({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-primary btn-xs">是</button>{/case}
                    {default /}<button onclick="change_recommend({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-secondary btn-xs">否</button>
                    {/switch}
                  </td>
                  <td>{$v.hits}</td>
                  <td>{$v.add_time}</td>
                  <td>
                    {switch $v.baijiahao}
                    {case 1 }<button onclick="sync_baijiahao({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-primary btn-xs">已同步</button>{/case}
                    {default /}<button onclick="sync_baijiahao({$v.id})" data-toggle="tooltip" title="点击可直接更换状态" class="btn btn-label btn-secondary btn-xs">未同步</button>
                    {/switch}
                  </td>
                  <td>{$v.last_time}</td>

                  <td>
                    <div class="btn-group">
                      <a target="_blank"  class="btn btn-xs btn-default" href="{:url('Uarticle/edit',['id'=>$v.id])}" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                      <button onclick="del({$v.id})" class="btn btn-xs btn-default" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></button>
                      <button type="button" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        高级操作 <span class="caret"></span>
                      </button>
                      <ul class="dropdown-menu" style="border: 1px #eee solid;box-shadow: 0px 13px 51px 0px;">
                        <li><a href="javascript:;" onclick="openframe('{:url('change_pid',['id'=>$v.id])}')">加入专题</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#!">加入专题</a></li>
                      </ul>
                    </div>
                  </td>
                </tr>
                {/foreach}

              </tbody>
            </table>
          </div>
          {$list|raw}
 
        </div>
      </div>
    </div>
    
  </div>
  
</div>
{include file="public/afooter"}
<script>
//  新增
  function AddCate(obj) {
    var url = $(obj).attr('href');
    layer.open({
      title:"新增分类",
      type: 2,
      area: ['500px', '450px'],
      fixed: false, //不固定
      maxmin: true,
      content: url
    });
  }

  //更新sitemap
$('#sitemap').click(function(){
  var url="{:url('AdminArticle/sitemap')}";
  $.post(url,{ids:1},function (e) {
    if(e.code ==200){
      success(e.msg);
      setTimeout(location.reload(),3000);
    } else {
      error(e.msg);
    }
  })
})

  //推送到百度站长平台
$('#dosubmit').click(function(){
  var checkID = [];//定义一个空数组
  $("input[name='ids[]']:checked").each(function(i){
    //把所有被选中的复选框的值存入数组
    checkID[i] =$(this).val();
  });
//  console.log(checkID);
  var url="{:url('AdminArticle/push_to_baidu_all')}";
  $.post(url,{ids:checkID},function (e) {
    if(e.code ==200){
      success(e.msg);
      setTimeout(location.reload(),3000);
    } else {
      error(e.msg);
    }
  })
})
//修改
//  function edit(obj) {
//    var url = $(obj).attr('href');
//    layer.open({
//      title:"修改",
//      type: 2,
//      area: ['500px', '450px'],
//      fixed: false, //不固定
//      maxmin: true,
//      content: url
//    });
//  }
//  删除
  function del(id) {
    layer.confirm('您确定要删除吗？', {
      btn: ['确定','取消'] //按钮
    }, function(){
      var url = "{:url('delete')}"
      $.post(url,{id:id},function (e) {
        if(e.code != 200){
          error(e.msg);
        }else {
          success(e.msg);
          var index = parent.layer.getFrameIndex(window.name);
          setTimeout(function(){parent.layer.close(index)}, 1000);
          window.parent.location.reload();
        }
      })
    }, function(){
      layer.msg('已取消');
    });
  }

  //修改置顶状态
  function change_top(id) {
    var url ="{:url('change_top')}";
    $.post(url,{id:id},function (e) {
      if(e.code ==200){
        success(e.msg);
        setTimeout(location.reload(),1000);
      } else {
        error(e.msg);
      }
    })
  }
  //修改推荐状态

function change_recommend(id) {
  var url ="{:url('change_recommend')}";
  $.post(url,{id:id},function (e) {
    if(e.code ==200){
      success(e.msg);
      setTimeout(location.reload(),1000);
    } else {
      error(e.msg);
    }
  })
}

function sync_baijiahao(id) {
    var url ="{:url('sync_baijiahao')}";
    $.post(url,{id:id},function (e) {
        if(e.code ==200){
            success(e.msg);
            setTimeout(location.reload(),1000);
        } else {
            error(e.msg);
        }
    })
}

function del_all() {
    var checkID = [];//定义一个空数组
    $("input[name='ids[]']:checked").each(function(i){
        //把所有被选中的复选框的值存入数组
        checkID[i] =$(this).val();
    });
    var url="{:url('del_all')}";

    layer.confirm('您确定要删除选中项吗，删除后不可恢复哦？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        var url = "{:url('del_all')}"
        $.post(url,{ids:checkID},function (e) {
            if(e.code ==200){
                success(e.msg);
                setTimeout(location.reload(),3000);
            } else {
                error(e.msg);
            }
        })
    }, function(){
        layer.msg('已取消');
    });



}
</script>

{/block}